<HTML>
    <HEAD>
        <TITLE>Genesys Team Report. ver 2.0 (c)Pavel Usim</TITLE>
        <link rel="stylesheet" type="text/css" href="def.css" />
        <script type="text/javascript" src="calendarDateInput.js"></script>
        <script type="text/javascript">
            function selectAll(x) {
                for(var i=0,l=x.form.length; i<l; i++)
                    if(x.form[i].type == 'checkbox' && x.form[i].name != 'sAll')
                        x.form[i].checked=x.form[i].checked?false:true
            }
        </script>
    </HEAD>
    <BODY>
        <img align ="right" alt ="Genesys" src="img\GenesysLogo.png">
        <p align="center">
            <a name="top">Genesys Team Report. ver 2.0</a><BR>
            Based on data exported from Siebel.
        </p>
        <?php
        require 'dbconnect.php';

        // returns IP
        function getIP() {
            if (isset($_SERVER['HTTP_X_REAL_IP']))
                return $_SERVER['HTTP_X_REAL_IP'];
            return $_SERVER['REMOTE_ADDR'];
        }

//  TODO(:) Reports: on TSE: closed by Product, by Priority, by Reason Code
//  TODO(:) Reports: on Customer/Account: Cust Sat by Customer/Acc,
//  TODO(:) Report on products(how many SRS / How many on T3 / how many active TSE on the product)
//  TODO(:) Analytic Report on KCS doc and Products in linked SRs. (if product do not much then verify)
//  TODO(:) Customer Sat report for/by cusomers accounts / for a engenner by castomers accounts.
//  TODO(:) Report how many SRS (by products) were opened to the engineer in the period.

        if (getIP() == '::1' or getIP() == '192.168.83.96') $debug = true;

        $result = mysql_query('select max(modified) as max from srs');
        $res = mysql_fetch_assoc($result);
        echo '<p align="center">ACTUAL ON: ' . date("r", $res['max']) . '</p>';
        mysql_free_result($result);


        echo 'choose reports:';

        echo '<form name="choosreports" action="index1.php" method=POST>';
        
        echo '<input type=\'radio\' name=\'_period\' value=\'on\' checked>Period Report<br>';
        echo '<input type=\'radio\' name=\'_period\' value=\'high\'>Detailed period Report<br>';

        // picks dates for period report
        $today = getdate();

        if ($today['mday'] > 20) {
            $fromMO = $today['mon'];
            $fromYY = $today['year'];
            $tillYY = $today['year'];
            $tillMO = $today['mon'] + 1;
        }
        if ($today['mday'] <= 20) {
            $fromMO = $today['mon'] - 1;
            $fromYY = $today['year'];
            $tillYY = $today['year'];
            $tillMO = $today['mon'];
        }
        if ($today['mon'] == 12 AND $today['mday'] > 20) {
            $fromMO = 12;
            $fromYY = $today['year'];
            $tillYY = $today['year'] + 1;
            $tillMO = 1;
        }
        if ($today['mon'] == 1 AND $today['mday'] < 20) {
            $fromMO = 12;
            $fromYY = $today['year'] - 1;
            $tillYY = $today['year'];
            $tillMO = 1;
        }

        // TILL date is not included in the report
        echo '<br>From <script>DateInput(\'_since\', true, \'MM/DD/YYYY\', \'' . $fromMO . '/20/' . $fromYY . '\')</script>';
        echo ' Till (not included) <script>DateInput(\'_till\', true, \'MM/DD/YYYY\', \'' . $tillMO . '/20/' . $tillYY . '\')</script><br>';
        echo '<input name=\'_products\' type=\'checkbox\'';
        if ($_COOKIE['_products'] == 'on')
            echo ' checked'; echo '>Report by products<br>';
        echo '<input name=\'_monthly\' type=\'checkbox\'';
        if ($_COOKIE['_monthly'] == 'on')
            echo ' checked'; echo '>Monthly Graph report<br>';
        echo '<input name=\'_reason\' type=\'checkbox\'';
        if ($_COOKIE['_reason'] == 'on')
            echo ' checked'; echo '>Reason Code Report<br>';    
        echo '<input name=\'_current\' type=\'checkbox\'';
        if ($_COOKIE['_current'] == 'on')
            echo ' checked'; echo '>Open SRs report<br>';    

        //echo '<input name=\'y_custsat\' type=\'checkbox\''; if ($_COOKIE['y_custsat']=='on') echo ' checked'; echo '>Customer satisfaction yearly report<br>';
        //echo '<input name=\'m_custsat\' type=\'checkbox\''; if ($_COOKIE['m_custsat']=='on') echo ' checked'; echo '>Customer satisfaction monthly report<br>';
        //echo '<input name=\'w_closed\' type=\'checkbox\''; if ($_COOKIE['w_closed']=='on') echo ' checked'; echo '>SR Closure Rate, weekly report<br>';
        //for last all - 4 - 3 - 2 - <<<1>>> week(s)
        //echo '<input name=\'m_closed\' type=\'checkbox\''; if ($_COOKIE['m_closed']=='on') echo ' checked'; echo '>SR Closure Rate, monthly report <img src="img/new.gif"><br>';
        //echo '<input name=\'q_closed\' type=\'checkbox\''; if ($_COOKIE['q_closed']=='on') echo ' checked'; echo '>SR Closure Rate, quarterly report<br>';
        //echo '<input name=\'y_closed\' type=\'checkbox\''; if ($_COOKIE['y_closed']=='on') echo ' checked'; echo '>SR Closure Rate, yearly report<br>';
        //echo '<input name=\'current\' type=\'checkbox\''; if ($_COOKIE['current']=='on') echo ' checked'; echo '>Current SRs<br>';

        echo '<br>choose engineers:<br>';
        echo '<input type="submit" value="submit">';
        $result = mysql_query('select team, count(tse_name) from tse group by team order by team');
        echo '<table><TR>';
        while ($row = mysql_fetch_assoc($result)) {
            echo '<TD class="left">' . $row['team'] . '(' . $row['count(tse_name)'] . ') team</TD>';
            $query = 'select owner_id, tse_name from tse where team = \'' . $row['team'] . '\' order by tse_name';
            $result1 = mysql_query($query);
            $tablestring .= '<TD class="left">';
            while ($row1 = mysql_fetch_assoc($result1)) {
                $tablestring .= '<input name=\'' . $row1['owner_id'] . '\' type=\'checkbox\'';
                if ($_COOKIE[$row1['owner_id']] == 'on')
                    $tablestring .= ' checked';
                $tablestring .= '>' . $row1['tse_name'] . '</br>';
            }
            $tablestring .= '</TD>';
        }
        echo '</TR><TR class="left">' . $tablestring . '</TR></table>';
        echo '</form>';
        ?>
    </BODY>
</HTML>